starter
  .factory('httpInterceptor', httpInterceptor)
  .config(function($httpProvider) {
    // 启用ajax拦截器
    $httpProvider.interceptors.push('httpInterceptor');
  });

function httpInterceptor($q, $rootScope) {
  return {
    request: function(config) {
      // do something on success
      if (/qss/.test(config.url)) {
        config.url = $rootScope.serverIp + config.url;
        config.withCredentials = true;
      }
      return config;
    },
    response: function(response) {
      return response;
    },
    responseError: function(rejection) {
      var data = rejection.data;
      if (rejection.status == -1) {
        $rootScope.showAlert('网络异常');
      }
      if (data && data.errorCode == '00100001') { // 没有登陆
        $rootScope.isLogined = false;
        // // 清空用户本地token存储的信息
        // localStorage.removeItem('userInfo');
        // // 全局事件，方便其他view获取该事件，并给以相应的提示或处理
        // $rootScope.$emit("ajaxIntercepted","notLogin",response);
        location.href = '#/login'
      } else if (data && data.errorCode == '00100002') { // 没有权限
      }
      return $q.reject(rejection);
    }
  };
}